<?php
require_once "my_profile_left_pane.php";

	
	
	if($_SESSION['user_id_sess']=="") {
		echo "<script type='text/javascript'> window.location='index.php?signin&url=profile'; </script>";
	}
	require_once "includes/class/member_management.class.php";
	$userId = $_SESSION['user_id_sess'];	
	$usrObj = new member_management;
	
	
	if(isset($_POST['editProfile'])) {
		
		$password		=	$_REQUEST['password'];
		$secret_question	=	$_REQUEST['secretQuestion'];
		$secret_answer		=	$_REQUEST['secretAnswer'];
		
		
		
		$sqlUpdUsr = "UPDATE tbl_users SET
			password='".$password."',
			secret_question='".$secret_question."',
			secret_answer='".$secret_answer."'
			WHERE user_id='$userId'";
		$rstUpdUsr = mysql_query($sqlUpdUsr) or die(mysql_error());
		if($rstUpdUsr) {
			$subject="Your Login Info Updated Successfully";
			$message="Dear ".$_REQUEST['fname']." ".$_REQUEST['lname'].",<br><br>
You have updated your login information successfully. As a tip you should change your password once in a while and have your password contain numbers and letters for extra protection. <br><br>Thank you<br><br>Swapen Team";
			$headers = "From: Swapen.com<mail@swapen.com> \r\n";
			$headers .= 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
			mail($_REQUEST['email'],$subject, $message, $headers);
 
			$msg = "<font color='#006600'>Your profile updated successfully.</font>";
		}
		else { $msg=""; }					
	}
	
	$userInfo = $usrObj->getMemberById($userId);
	
?>
<script src="<?php echo $base_url?>js/jquery.custom_radio_checkbox.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
	$(".radio").dgStyle();
	$(".checkbox").dgStyle();
});
</script>
<div class="releftbox_out">
	<div class="releftbox_top">&nbsp;</div>
	<div class="releftbox_repeat">
		<h1 style="float:left; width:100%; text-align:center; margin-top:-10px;">My Login Info</h1>
		<span style="float:left; width:96%; text-align:right; padding:0px5px 5px 0px;"><a href="javascript:void(0);">FAQ</a></span>
		<div id="messageAreaTop" style="margin:10px 0px 10px 20px; float:left;"><?php if(isset($msg)) echo "<b>".$msg."</b>"; ?></div>
		<form enctype="multipart/form-data" name="frmEditProfile" method="post" action="" onSubmit="return validateForm();">
		<input type="hidden" name="fname" value="<?php echo $userInfo['first_name']; ?>" />
		<input type="hidden" name="lname" value="<?php echo $userInfo['last_name']; ?>" />
		<input type="hidden" name="email" value="<?php echo $userInfo['email']; ?>" />
		<div class="blue_box">
			<div class="bluebar_left"></div>
			<div class="bluebar_center"><span>User Info</span></div>
			<div class="bluebar_right"></div>
		</div>
		
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="username" id="lblUserName">Username:</label>
				<span style="padding-top:7px"> <b><?php echo $userInfo['username']; ?></b></span>
			</div>
		</div>
		
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="password" id="lblPassword">Change Password:</label>
				<span><input type="password" name="password" id="password1" style="width:200px;" class="inputbg" value="<?php echo $userInfo['password']; ?>" /></span>
			</div>
		</div>
		
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="password" id="lblConfirmPassword">Re-enter New Password:</label>
				<span><input type="password" name="confirmPassword" id="confirmPassword1" style="width:200px;" class="inputbg" value="<?php echo $userInfo['password']; ?>" /></span>
			</div>
		</div>
		
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="secretQuestion" id="lblSecretQuestion">Pick a secret question:</label>
				<span>
					<select name="secretQuestion" id="secretQuestion" style="width:300px; height:28px;" class="inputbg">
						<option value="">Select a secret question</option>
						<?php
						$sqlSelQuestion = "select * from tbl_questions";
						$rstSelQuestion = mysql_query($sqlSelQuestion) or die(mysql_error());
						while($rowSelQuestion = mysql_fetch_array($rstSelQuestion))
						{ ?>
						<option value="<?php echo $rowSelQuestion['question_id'] ?>"><?php echo $rowSelQuestion['question'] ?></option>
						<?php } ?>
					</select>
					<script>$('#secretQuestion').val(<?php echo $userInfo['secret_question']; ?>)</script>
				</span>
			</div>
			
		</div>
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="secretAnswer" id="lblSecretAnswer">Your seceret answer:</label>
				<span>
				
				<input value="<?php echo $userInfo['secret_answer']; ?>" type="password" name="secretAnswer" id="secretAnswer" class="inputbg" style="width:300px;" />
				
				</span>
			</div>
		</div>
		
		<div class="blue_box">
			&nbsp;
		</div>
		<div class="blue_box">
			<div class="form_field_box_full">
				<div class="checkbox"><input name="accept" id="accept" type="checkbox" /> </div> &nbsp;&nbsp;
				<label style="text-align:left;">I agree that:</label>
				<div id="lblAgreement" style="display:none; color:#FF0000; font-weight:bold">Acceptance of  agreement is must to register. </div>
			</div>
			<br /><br /><br />
			<ul>
				<li>I accept the <a href="" tabindex="1">User Agreement</a> and <a href="index.php?policy" target="_blank">Privacy Policy</a>.</li>
				<li>I may receive communications from swapen.</li>
				<li>I'm at least 18 years old.</li>
			</ul>
		</div>
		<div class="blue_box" style="text-align:center;">
			<input type="submit" name="editProfile" id="editProfile" value="UPDATE" class="sbmt_btn" />
		</div>
		<div id="errMsg" style="margin:10px 0px 10px 20px; float:left;"></div>
		</form>
	</div>
		
	<div class="releftbox_bot">&nbsp;</div>
</div>		
<script>

function validateForm()
{
	var flag=0;
	if($('#password1').val()=='')
	{
		flag=flag+1; 
		$('#lblPassword').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblPassword').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#confirmPassword1').val()=='')
	{
		flag=flag+1; 
		$('#lblConfirmPassword').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblConfirmPassword').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#password1').val() != $('#confirmPassword1').val())
	{
		flag=flag+1; alert($('#password1').val()+' :: '+$('#confirmPassword1').val());
		$('#lblPassword').css({'font-weight':'bold','color':'#FF0000'});
		$('#lblConfirmPassword').css({'font-weight':'bold','color':'#FF0000'});
	}
	else{
		$('#lblPassword').css({'font-weight':'normal','color':'#666666'});
		$('#lblConfirmPassword').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#secretQuestion').val()=='')
	{
		flag=flag+1;
		$('#lblSecretQuestion').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblSecretQuestion').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#secretAnswer').val()=='')
	{
		flag=flag+1;
		$('#lblSecretAnswer').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblSecretAnswer').css({'font-weight':'normal','color':'#666666'});
	}
	
	
	if($("#accept").is(":checked")==false)
	{
		flag=flag+1;
		alert('You have to agree our conditions before submiting your data.');
	}
	
	if(flag>0)
	{
		$('#errMsg').html("<font color='#FF0000'><b>We need some additional information from you. Enter valid information in red color highlighted fields and try again.</b></font>");
		return false;
	}
	else
	{
		$('#errMsg').html('');
		
		return true;
	}
}
</script>		
		
